<template>
  <div>
    <van-cell class="cell">
      <router-link :to="'/dish/' + did" class="dish-box">
        <!-- 标题区域的插槽 -->
        <div class="info-box">
          <!-- 单张图片 -->
          <img :src="cover[0]" alt="" class="thumb" />
          
          <!-- 标题 -->
          <div class="title-box">
            <span>{{ dishName }}</span>
            <div class="label-box">
              <!-- 标签 -->
              <van-tag
                class="label"
                size="medium"
                round
                type="success"
                v-for="(item, i) in labels"
                :key="i"
              >
                {{ labels[i].labelName }}
              </van-tag>
            </div>
            <!-- 价格 -->
            <span class="price"
              ><span style="font-size: 14px">￥</span>{{ price }}</span
            >
            <!-- 浏览时间 -->
            <span class="create-time">
              {{ formattedTime }}
            </span>
          </div>
        </div>
      </router-link>
    </van-cell>
  </div>
</template>

<script>
// import request from "@/utils/request";
import moment from "moment";

export default {
  name: "DishSearchInfo",
  data() {
    return {
      // baseURL: request.defaults.baseURL,
    };
  },
  // 自定义属性
  props: {
    // 菜品id
    did: {
      type: String,
      default: "",
    },
    // 名字
    dishName: {
      type: String,
      default: "",
    },
    // 价格
    price: {
      type: Number,
      default: 0.0,
    },
    // 封面的信息对象
    cover: {
      require: false,
      type: Array,
      default: function () {
        return [];
      },
    },
    // 标签
    labels: {
      type: Array,
      default: function () {
        return [];
      },
    },
    time: {
      type: String
    },
  },
  computed: {
    formattedTime() {
      return moment(this.time).format("YYYY-MM-DD HH:mm:ss");
    },
  },
};
</script>

<style lang="less" scoped>
.label-box {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.thumb {
  // 矩形黄金比例：0.618
  width: 123px;
  height: 80px;
  margin: auto 10px;
  background-color: #f8f8f8;
  object-fit: cover;
}
.cell {
  border-style: solid;
  border-width: 0 0 1px 0;
  border-color: rgba(red, green, blue, 0.2);
}
.info-box {
  display: flex;
  flex-direction: row;
}
.title-box {
  display: flex;
  padding: 10px;
  flex-direction: column;
  justify-content: space-between;
  align-items: flex-start;
  .dish-name {
    font-size: 18px;
    color: #222226;
  }
  .label-box {
    display: flex;
    flex-direction: row;
    /deep/ .label {
      margin-right: 3px;
    }
  }
  .price {
    font-size: 22px;
    color: #fe2c24;
    font-weight: 700;
  }
}

.thumb-box {
  display: flex;
  justify-content: space-between;
}
.create-time {
  font-size: 12px;
  color: #2222268e;
}
</style>